<!-- 加工检验查询 -->
<template>
  <div>
    <el-button-group style="margin-bottom: 10px;">
      <el-button type="primary" icon="el-icon-search" @click="searchHandle">查找</el-button>
      <el-button type="primary" icon="el-icon-delete" @click="searchReset">清空</el-button>
    </el-button-group>
    <el-form inline label-width="100px" @keyup.enter.native="searchHandle">

      <el-form-item label="配镜单号">
        <el-input v-model="dataForm.saleBillId"></el-input>
      </el-form-item>

      <el-form-item label="销售日期">
        <el-row>
          <el-col :span="11">
            <el-date-picker v-model="dataForm.saleTimeStart" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
          </el-col>
          <el-col class="line" :span="2" style="text-align: center;">-</el-col>
          <el-col :span="11">
            <el-date-picker v-model="dataForm.saleTimeEnd" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
          </el-col>
        </el-row>
      </el-form-item>

      <el-form-item label="顾客姓名">
        <el-input v-model="dataForm.customerName"></el-input>
      </el-form-item>

      <el-form-item label="销售部门" prop="deptId">
        <el-select v-model="dataForm.deptId" placeholder="请选择部门" size="mini">
          <el-option v-for="item in deptOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="取镜时间">
        <el-row>
          <el-col :span="11">
            <el-date-picker v-model="dataForm.takeMirroTimeStart" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
          </el-col>
          <el-col class="line" :span="2" style="text-align: center;">-</el-col>
          <el-col :span="11">
            <el-date-picker v-model="dataForm.takeMirroTimeEnd" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
          </el-col>
        </el-row>
      </el-form-item>

      <el-form-item label="检验师">
        <el-input v-model="dataForm.checkUserName"></el-input>
      </el-form-item>

      <el-form-item label="加工师">
        <el-input v-model="dataForm.workUserName"></el-input>
      </el-form-item>
      <el-form-item label="检验日期">
        <el-row>
          <el-col :span="11">
            <el-date-picker v-model="dataForm.checkTimeStart" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
          </el-col>
          <el-col class="line" :span="2" style="text-align: center;">-</el-col>
          <el-col :span="11">
            <el-date-picker v-model="dataForm.checkTimeEnd" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
          </el-col>
        </el-row>
      </el-form-item>
    </el-form>

    <div class="avue-crud">
      <el-table :data="dataList" border v-loading="dataListLoading" :max-height="tableHeight">
        <el-table-column prop="saleBillId" label="配镜单号">
          <template slot-scope="scope">
            <el-button type="text" @click="checkDetailByOrder(scope.row.saleBillId)">{{scope.row.saleBillId}}</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="customerName" label="顾客姓名"></el-table-column>
        <el-table-column prop="workUserName" label="加工师"></el-table-column>
        <el-table-column prop="checkUserName" label="检验师"></el-table-column>
        <el-table-column prop="checkTime" label="检验日期"></el-table-column>
        <el-table-column prop="takeMirroTime" label="取镜时间"></el-table-column>
        <el-table-column label="操作" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" icon="el-icon-edit" @click="viewInfo(scope.row.saleId)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="avue-crud__pagination">
      <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" background layout="total, sizes, prev, pager, next"></el-pagination>
    </div>
    <check-form v-if="checkFormVisible" ref="checkForm" @refreshDataList="getDataList"></check-form>
    <order-info v-if="infoVisible" ref="infoDialog"></order-info>
  </div>
</template>

<script>
  import { mapGetters } from "vuex"
  import { workCheckedFetchList } from "@/api/eims/formalInspect"
  import { getDeptInfoByDeptType } from '@/api/admin/dept'

  import CheckForm from "./FormCheckPrint"
  import OrderInfo from '@/views/eims/optician/glassesinfo/detail'

  export default {
    props: ['tableHeight'],
    data() {
      return {
        dataForm: {},
        dataList: [],
        deptOptions: [],
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        dataListLoading: false,
        addOrUpdateVisible: false,
        checkFormVisible: false,
        infoVisible: false,
        searchForm: {
          saleId: "",
          customerName: "",
          deptId: ""
        }
      };
    },
    computed: {
      ...mapGetters(["permissions"])
    },
    components: {
      CheckForm,
      OrderInfo
    },
    methods: {
      init() {
        this.getDataList()
        this.getDeptList()
      },
      //	查询数据
      searchHandle() {
        this.pageIndex = 1
        this.getDataList()
      },
      // 清空搜索框
      searchReset() {
        for (let key in this.dataForm) {
          this.dataForm[key] = ''
        }
      },
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true;
        let params = {
          current: this.pageIndex,
          size: this.pageSize
        };
        workCheckedFetchList(Object.assign(params, this.dataForm)).then(response => {
          if(response.data.code == '0'){
            this.dataList = response.data.data.records
            this.totalPage = response.data.data.total
          }else{
            this.$message.error(response.data.msg)
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val;
        this.pageIndex = 1;
        this.getDataList();
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val;
        this.getDataList();
      },
      // 详情按钮
      viewInfo(saleId) {
        this.checkFormVisible = true;
        this.$nextTick(() => {
          this.$refs.checkForm.init(saleId)
        })
      },
      //  查看配镜单详情
      checkDetailByOrder(order) {
        this.infoVisible = true;
        this.$nextTick(() => {
          this.$refs.infoDialog.init('', order, '配镜单详情');
        });
      },
      getDeptList() {
        getDeptInfoByDeptType(1).then(response => {
          if(response.data.code == '0'){
            let result = response.data.data
            let list = []
            result.forEach(item => {
              list.push({
                value: item.id,
                label: item.name
              })
            })
            this.deptOptions = list
          }else{
            this.$message.error(response.data.msg)
          }
        })
      }
    }
  }
</script>
